﻿using System;
using System.Collections.Generic;
using System.IO;

namespace ManagedTFRecordLibrary
{
    public sealed class Example
    {
        public Dictionary<string, Feature> Features { get; internal set; } = new Dictionary<string, Feature>();

        public ArraySegment<byte> SerializeToArray()
        {
            using (var ms = new MemoryStream(81920))
            {
                ProtoBuf.Serializer.Serialize(ms, ExampleConverter.ConvertToTFExample(this));
                if (ms.TryGetBuffer(out var result))
                {
                    return result;
                }
                return new ArraySegment<byte>(ms.ToArray());
            }
        }
    }

    public sealed class SequenceExample
    {
        public Dictionary<string, Feature> Context { get; } = new Dictionary<string, Feature>();
        public Dictionary<string, List<Feature>> FeatureLists { get; set; }
    }

    public abstract class Feature
    {

    }

    public sealed class BytesListFeature : Feature
    {
        public BytesListFeature(List<byte[]> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }
            Values = values;
        }
        public List<byte[]> Values { get; private set; }
    }
    public sealed class FloatListFeature : Feature
    {
        public FloatListFeature(float[] values)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            Values = values;
        }
        public float[] Values { get; private set; }
    }
    public sealed class Int64ListFeature : Feature
    {
        public Int64ListFeature(long[] values)
        {
            Values = values;
        }
        public long[] Values { get; private set; }
    }
}
